<?php

namespace App\Http\Requests\Auth;

use App\Http\Requests\BaseRequest;
use Illuminate\Auth\Events\Lockout;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;

class LoginRequest extends BaseRequest
{
    public array $scenes = [
        'register' => ['phone', 'name', 'verificationcode'],
        'find' => ['phone', 'card_no','password']
    ];

    public function findRules(){
        return [
            'phone' => 'required|regex:/1[3456789]{1}\d{9}$/',
            'password' => ['required', 'alpha_dash', 'min:6'],
            'name' => ['required'],
            'verificationcode' => ['required'],
            'card_no' => ['required', 'numeric', 'digits:13'],
        ];
    }
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'phone' => 'required|regex:/1[3456789]{1}\d{9}$/|unique:App\Models\User,phone',
            'password' => ['required', 'alpha_dash', 'min:6'],
            'card_no' => ['required', 'numeric', 'digits:13', 'unique:App\Models\User,card_no'],
            'name' => ['required'],
            'verificationcode' => ['required'],
        ];
    }

    public function messages(): array
    {
        return [
            'phone.required' => '请输入手机号码',
            'phone.regex' => '手机号码不正确',
            'phone.unique' => '手机号码已经存在',
            'verificationcode.required' => '验证码不能为空',
            'name.required' => '姓名不能为空',
            'password.required' => '请填写密码',
            'password.alpha_dash' => '密码格式不正确',
            'password.min' => '密码最少6位',
            'card_no.required' => '请填写卡号',
            'card_no.alpha_dash' => '卡号格式不正确',
            'card_no.digits' => '卡号为13位数字',
            'card_no.unique' => '卡号已经存在',
        ];
    }
}
